#pragma once

#include <QSound>
#include <QTimer>
#include <QWidget>
#include "Const.h"
#include "Snake.h"

// 游戏
class Game: public QObject {
    Q_OBJECT

    // 状态
    public: enum Status {
        END,    // 已结束
        PAUSED, // 暂停中
        PLAYING // 游戏中
    };

    signals: void UM_SCORE(int);            // 得分事件
    signals: void UM_DIFFICULTY_UP(int);    // 难度增加事件
    signals: void UM_GAME_OVER(bool);       // 游戏结束事件

    private: SnakeBody* mApple;     // 果子
    private: QPixmap* mBitmap;      // 后台缓冲位图
    private: int mDifficulty;       // 难度
    private: QPainter mDrawer;      // 绘图者
    private: bool mEnableMusic;     // 音乐开关
    private: QWidget* mGameBoard;   // 游戏区域
    private: QSound mMusicPlayer;   // 音乐播放者
    private: int mScore;            // 得分
    private: Snake* mSnake;         // 蛇
    private: Status mStatus;        // 状态
    private: QTimer mTimer;         // 定时器

    public: Game(QPixmap*, QWidget*);
    private: void createApple();
    private: void drawGameBoard();
    private: void gameOver(bool);
    public: Status getStatus();
    private: bool isWon();
    public: void onKeyPressed(int);
    private slots: void onTimer();
    public: void pause();
    public: bool playMusic();
    private: bool pointIsUsed(QPoint*);
    public: void start();
};
